var HomePageEvent = new EventMVC ('eventlist');
var EventDetailEvent = new EventMVC ('eventform');
var RoomListEvent = new EventMVC ('roomlist');;
var UserListEvent = new EventMVC ('userlist');
var LoginScreenEvent = new EventMVC ('loginform');
var EventLogScreen = new EventMVC ('eventlog');
var SettingsPageEvent = new EventMVC ('settingspage');
var CalendarPageEvent = new EventMVC ('calendarpage');
var InvoicePageEvent = new EventMVC ('invoicepage');
var ErrorReportEvent = new EventMVC ('googlepage');
var ErrorLogEvent = new EventMVC ('errorlogpage');
var WindowAlert = new EventMVC ('alertwindow');
var WindowEmail = new EventMVC ('mailwindow');
 
// WindowAlertView
var WindowAlertView = new ViewMVC ('alertwindow', 'derrorspace', DisplayWindowAlert, null, OnDisplayWindowAlert );
 
// WindowAlertView
var WindowEmailView = new ViewMVC ('mailwindow', 'derrorspace', DisplayWindowEmail, null, OnDisplayWindowAlert );
 
function OnDisplayWindowAlert ()
{ 
	var ds=document.getElementById ('alertcover');
	if (ds)
	{
		ds.invoke = function (x)
		{   
			this.style.width = window_w();
			this.style.height = window_h(); 
			this.style.display = window.mcvevent == 'alertwindow' ? 'inline' : 'none' 
		}
		window.resizer.subscribe (ds); 
	} 
}
 

function CloseWindowAlert ()
{ 
	var ds=document.getElementById ('derrorspace');
	if (ds)
	{
		ds.style.display = 'none'; 
		Controller.moreinfo=null;
		Controller.message=null;
		Controller.mvcevents[window.lastevent].invoke();
	} 
}
 

function DisplayWindowEmail ()
{ 
	if (Controller.message) return Factory.write ( {'template' : 'codewindow', 'message' : Controller.message, 'subject' : Controller.subject, 'to' : Controller.to} );
	else return '';
}

function DisplayWindowAlert ()
{ 
	if (Controller.message) return Factory.write ( {'template' : 'messagebox', 'message' : Controller.message, 'moreinfo' : Controller.moreinfo} );
	else return '';
}

window.alert = function (x) 
{ 
	Controller.moreinfo=null;
	Controller.message=x;
	window.lastevent = window.mvcevent; 
	WindowAlert.invoke ();
}
 
// ErrorReportView
var ErrorReportView = new ViewMVC ('googlepage', 'dworkspace', DisplayErrorReportForm, null, OnDisplayErrorReport );
 
// ErrorLogView 
var ErrorLogView = new ViewMVC ('googlepage', 'dworkspace', DisplayErrorReportList, null, OnDisplayErrorReport ); 
 
// InvoicePageView
var InvoicePageView = new ViewMVC ('invoicepage', 'dworkspace', ProcessInvoiceListResult); 
InvoicePageView.afterinvoke = function () { AttachResizer ('dceivtable', (Controller.SidebarState==1?176:20), 100); } 
 
// CalendarPageView
var CalendarPageView = new ViewMVC ('calendarpage', 'dworkspace', RenderSettingsPage); 

// SettingsPageView
var SettingsPageView = new ViewMVC ('settingspage', 'dworkspace', RenderSettingsPage, null, OnSettingsPageRender); 

// SettingsPageSidebar
var SettingsPageSidebar = new ViewMVC ('settingsbar', 'dsidebarnav', function () { return ''; }); 

// EventLogView
var EventLogView = new ViewMVC ('eventlog', 'dworkspace',ProcessEventLogResult,null,function () { AttachResizer ('dcelogtable', 176); }); 

// UserListView
var UserListView = new ViewMVC ('userlist', 'dworkspace',ProcessUserListResult,null,OnUserListRender); 

// RoomListView
var RoomListView = new ViewMVC ('roomlist', 'dworkspace',ProcessRoomListResult); 
RoomListEvent.afterinvoke = function ()  { AttachResizer ('dceroomtable', (Controller.SidebarState==1?176:20), 120); }

// LoginScreenView
var LoginScreenView = new ViewMVC ('loginform', 'dworkspace',LoginScreen,null,OnLoginScreenRender);  

// DebugEventDataGrid
var DebugEventDataGrid = new ViewMVC ('eventlist', 'dworkspace',ProcessEventListResult,BeforeEventListRender,OnEventListRender);  

// DebugEventDetailForm
var DebugEventDetailForm = new ViewMVC ('eventform', 'dworkspace',ProcessEventFormResult,null,AttachEventFormElements);  

// DebugToolBar
var DebugToolBar = new ViewMVC ('toolbar', 'dglobaltoolbar',ProcessUIToolbar); 

// DebugNavBar
var DebugNavBar = new ViewMVC ('sidebar', 'dsidebarnav',ProcessNavBarResult); 


WindowEmail.add (WindowEmailView); 
WindowAlert.add (WindowAlertView);  
HomePageEvent.add (DebugEventDataGrid, DebugNavBar, DebugToolBar);  
RoomListEvent.add (RoomListView,DebugToolBar,DebugNavBar);  
EventDetailEvent.add (DebugEventDetailForm,DebugNavBar,DebugToolBar);  
LoginScreenEvent.add (LoginScreenView); 
EventLogScreen.add (EventLogView,DebugToolBar);  
UserListEvent.add (UserListView,DebugToolBar);
SettingsPageEvent.add (SettingsPageView,SettingsPageSidebar,DebugToolBar); 
InvoicePageEvent.add (InvoicePageView, DebugToolBar); 
ErrorLogEvent.add (ErrorLogView, DebugToolBar); 
ErrorReportEvent.add (ErrorReportView, DebugToolBar);  